import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_uikit/widget/text/text_widget.dart';
import 'package:get/get.dart';
import '../common/app_text_style.dart';
import 'root_logic.dart';

class RootPage extends StatefulWidget {
  const RootPage({Key? key}) : super(key: key);

  @override
  State<RootPage> createState() => RootPageState();
}

class RootPageState extends State<RootPage> {
  final logic = Get.put(RootLogic());
  final state = Get.find<RootLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("Flutter_UIKit"),
      ),
      body: buildListWidget(),
    );
  }

  /// 构建列表组件
  Widget buildListWidget() {
    return ListView.builder(
      shrinkWrap: false,
      itemCount: state.dataList.length,
      itemBuilder: (context, index) {
        String title = state.dataList[index];
        return buildListItemWidget(title);
      },
    );
  }

  /// 构建列表Item
  Widget buildListItemWidget(String title) {
    return GestureDetector(
      onTap: () {
        logic.itemEvent(title);
      },
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.symmetric(horizontal: 16.w),
            height: 45.w,
            child: Row(
              children: [
                Expanded(child: TextWidget(title, TS_FFFF4D5C_14_W5)),
                Image.asset("assets/images/common_right_arrow.png",
                    width: 30.w, height: 30.w)
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 16.w),
            decoration: const BoxDecoration(
                border: Border(
                    bottom: BorderSide(width: 1, color: Color(0xFFE5E6EB)))),
          )
        ],
      ),
    );
  }
}
